package com.itheima.controller;

import com.itheima.entity.Result;
import com.itheima.pojo.LoginDto;
import com.itheima.utils.SendSms;
import com.itheima.utils.ValidateCodeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Random;

@RestController
@RequestMapping("/validateCode")
public class ValidateCodeController {

    @Autowired
    private HttpServletRequest request;

    @PostMapping("/send4Login.do")
    public void sendMsg(String telephone){
        //创建随机验证码
        String code = ValidateCodeUtils.generateValidateCode4String(6);
        System.out.println("短信验证码："+code);
        //调用阿里云短信API
//        SendSms.sendMsg(telephone,code );
        //把验证码存入session
        HttpSession session = request.getSession();
        session.setAttribute(telephone,code );

    }

    //移动端预约套餐发送验证码
    @PostMapping("/send4Order.do")
    public void sendOrderMsg(String telephone){
        //创建随机验证码
        String code = ValidateCodeUtils.generateValidateCode4String(6);
        System.out.println("预约检查验证码："+code);
        //把验证码存入session
        HttpSession session = request.getSession();
        session.setAttribute(telephone,code );
    }


}
